package com.siteseat.crudeq.broker.filter;

import java.util.List;

import com.siteseat.crudeq.broker.transport.BrokerSession;
import com.siteseat.common.foundation.Component;
import com.siteseat.common.foundation.PropertyHelper;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;

/**

 */
public class FilterManager extends Component {

  private List<Filter> filters;

  /**
   * Gets the filters
   * 
   * @return the filters
   */
  public List<Filter> getFilters() {
    return filters;
  }

  /**
   * Sets the filters
   * 
   * @param filters
   *          the filters to set
   */
  public void setFilters( List<Filter> filters ) {
    this.filters = filters;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected void doInit() throws Exception {
    PropertyHelper.ensureNotNull( log, getFilters(), "filters" );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected void doDestroy() throws Exception {
    // do nothing so far
  }
  
  /**
   * @param req
   * @param resp
   * @throws Exception
   */
  public void execute( BrokerSession session, byte reqId, Channel channel, ChannelBuffer channelBuffer )
          throws Exception {
    FilterChain chain = new FilterChain( getFilters().iterator() );
    chain.execute( chain, session, reqId, channel, channelBuffer );
  }

}
